<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>原型式继承</title>
	</head>
	<body>
		1、复制传入的对象到创建对象的原型上，从而实现继承
		2、缺点: 同原型链继承一样，每个实例对引用类型属性的修改都会被其他的实例共享
		<script type="text/javascript">
			
			function createObj(obj) {
				function F() {}
				F.prototype = obj;
				return new F();
			}
			
			var person = {
				name: 'bob',
				loveList: ['读书', '打游戏']
			}
			
			var person1 = createObj(person)
			var person2 = createObj(person)
			
			console.log(person1.name)  // bob
			person1.loveList.push('写代码1')
			console.log(person1.loveList) // ["读书", "打游戏", "写代码1"]
			console.log('person1',person1) 
			// person = {
				// name: 'bob',
				// loveList: ['读书', '打游戏', '写代码1', '写代码2']
			// }
			
			console.log(person2.name) // bob
			person2.loveList.push('写代码2')
			console.log(person2.loveList) //  ["读书", "打游戏", "写代码1", "写代码2"]
			console.log('person2',person2)
			// person = {
				// name: 'bob',
				// loveList: ['读书', '打游戏', '写代码1', '写代码2']
			// }
			
		</script>
	</body>
</html>
